#version 460
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_GOOGLE_include_directive : enable

// layout (push_constant) uniform SPushConstants
// {
//     //vp


// } PushConstants;

struct SModelBuffer
{
    mat4 Model;
};

#include "CppMacros.h"

layout (set=1, binding = 0) uniform ModelBufferBatch
{
    SModelBuffer Models[MESH_BATCH_SIZE];
} ModelBuffer;

layout (set=2, binding = 0) uniform SceneBufferObject
{
    mat4 ProjectionView;
    float CameraNear;
    float CameraFar;

    //其他参数无关紧要



} SceneBuffer;

//顶点属性
layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 inTexCoords;
layout (location = 2) in vec3 inVertexNormal;


layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec2 outUV;
layout (location = 2) out vec3 outWorldPos;
layout (location = 3) out float outCameraNear;
layout (location = 4) out float outCameraFar;


void main() 
{
    vec4 WorldPos=ModelBuffer.Models[gl_InstanceIndex].Model*vec4(pos,1);
    gl_Position = 
        SceneBuffer.ProjectionView  // project * view matrix
        * WorldPos;
    outUV=inTexCoords;
    outNormal= mat3(transpose(inverse(ModelBuffer.Models[gl_InstanceIndex].Model) ) ) * inVertexNormal; 
    outWorldPos=WorldPos.xyz;

    outCameraNear=SceneBuffer.CameraNear;
    outCameraFar=SceneBuffer.CameraFar;
}